define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function() {
		this.callParent();
		this.init = true;
	};

	Model.prototype.backBtnClick = function(event) {

		this.comp("wing1").showLeft();
	};

	Model.prototype.treeViewDataIndexChanged = function(event) {
		var id = event.row.val("fNodeId");
		var fromDate = this.comp("dateData").getValue("from");
		var toDate = this.comp("dateData").getValue("to");
		this.comp("hisData").setFilter('filter0', this.getFilter(id, fromDate, toDate));
		this.comp("hisData").refreshData();

	};

	Model.prototype.dateDataValueChange = function(event) {
		if(this.init == true)
			return;
		var id = this.comp("treeViewData").getValue("fNodeId");
		var fromDate = this.comp("dateData").getValue("from");
		var toDate = this.comp("dateData").getValue("to");
		this.comp("hisData").setFilter('filter0', this.getFilter(id, fromDate, toDate));
		this.comp("hisData").refreshData();
	};

	Model.prototype.getFilter = function(id, fromDate, toDate) {
		if (typeof (fromDate) == "undefined" || typeof (toDate) == "undefined" /*|| typeof (fromDate.value) == "undefined" || typeof (toDate.value) == "undefined"*/) {
			return "1=0";
		} else {
			fromDate.setHours(0, 0, 0, 0);
			toDate.setHours(23, 59, 59, 999);
		}
		var filter = "fPointID = '" + id + "' and fDate >= '" + justep.Date.toString(fromDate, justep.Date.STANDART_FORMAT_SHOT) + "' and fDate <= '" + justep.Date.toString(toDate, justep.Date.STANDART_FORMAT_SHOT) + "'";
		// debugger;
		return filter;
	};

	Model.prototype.modelLoad = function(event) {
		//debugger;
		var now = new Date();
		var yesterday = new Date();
		yesterday.setDate(yesterday.getDate() - 1);

		this.comp("dateData").setValue("from", yesterday);
		this.comp("dateData").setValue("to", now);
		this.init = false;
	};

	return Model;
});